# -*-coding: Utf-8 -*-
# @File : SinaPage.py .py
# author:
# Time：2024/3/15
from appium import webdriver
# from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support import expected_conditions as EC
# from appium.webdriver.common.touch_action import TouchAction
# from appium.webdriver.common.
import pyautogui
import time

from selenium.webdriver.support.wait import WebDriverWait


class AppPage:
    def __init__(self,driver):
        self.driver = driver
        time.sleep(5)


    def click_agreement(self):
        self. driver.find_element(AppiumBy.XPATH, '//android.widget.TextView[@text="同意并继续"]').click()
        time.sleep(5)

    def click_discover(self):
        # self.driver.tap([(721, 2444)],100)
        ele = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
            (AppiumBy.XPATH, '(//android.widget.FrameLayout[@content-desc="发现"])[13]')))
        ele.click()
        time.sleep(5)

    # def click_known(self):
    #     self.driver.tap([(708, 1933)],100)
    #     time.sleep(10)

    def click_search_box(self):
        # self.driver.tap([(733, 191)],100)
        self.driver.tap([(460, 73)], 100)
        time.sleep(5)


    def enter_search_box_send(self,keyword):
        # ele = self.driver.find_element(AppiumBy.ID, "com.sina.weibo:id/tv_search_keyword")
        # ele.send_keys(keyword)
        search_box = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(
            (AppiumBy.XPATH, '//android.widget.EditText[@resource-id="com.sina.weibo:id/tv_search_keyword"]')))
        search_box.send_keys(keyword)
        time.sleep(5)

    def perform_search(self):
        self.driver.press_keycode(66)
        time.sleep(5)


    def swipe_page(self):
        for i in range(5):
            self.driver.swipe(start_x=400,start_y=1200,end_x=400,end_y=300,duration=400)
            time.sleep(3)
